package org.web.demo.listener;

import lombok.extern.slf4j.Slf4j;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextAttributeEvent;
import javax.servlet.ServletContextAttributeListener;
import javax.servlet.annotation.WebListener;

/**
 * @author yexi
 */
@WebListener
@Slf4j
public class CustomServletContextAttributeListener implements ServletContextAttributeListener {

    @Override
    public void attributeAdded(ServletContextAttributeEvent scae) {
        Object source = scae.getSource();
        Object value = scae.getValue();
        String name = scae.getName();
        log.info("ServletContext增加了数据");
        log.info("监听到{}新增了属性{}={}", source, name, value);
    }

    @Override
    public void attributeRemoved(ServletContextAttributeEvent scae) {
        log.info("ServletContext删除了数据");
    }

    @Override
    public void attributeReplaced(ServletContextAttributeEvent scae) {
        log.info("ServletContext修改了数据");
    }
}
